package com.zhentao.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhentao.domain.YdDepotHead;
import com.zhentao.domain.YdMaterial;
import com.zhentao.domain.YdSupplier;
import com.zhentao.domain.dto.PurchaseOrderDto;
import com.zhentao.domain.vo.PurchaseOrderVO;
import com.zhentao.service.YdDepotHeadService;
import com.zhentao.service.YdMaterialService;
import com.zhentao.service.YdSupplierService;
import com.zhentao.util.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : mgh
 * @date : 2024-10-23 11:26
 * @effect : 当前类的作用是
 * @projectTeam :
 */
@RestController
public class PurchaseOrderController {

    @Resource
    private YdDepotHeadService ydDepotHeadService;
    @Resource
    private YdSupplierService ydSupplierService;
    @Resource
    private YdMaterialService ydMaterialService;

    /**
     * 查询采购订单列表
     * @param dto
     * @return
     */
    @PostMapping("purchaseOrderList")
    public Result purchaseOrderList(@RequestBody PurchaseOrderDto dto){
        return ydDepotHeadService.purchaseOrderList(dto);
    }
    @PostMapping("purchaseCGRK")
    public Result purchaseCGRK(@RequestBody PurchaseOrderDto dto){
        return ydDepotHeadService.purchaseCGRK(dto);
    }

    /**
     * 查询供应商
     * @return
     */
    @PostMapping("/supplierGYSList")
    public Result supplierList(){
        LambdaQueryWrapper<YdSupplier> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(YdSupplier::getType,"供应商");
        List<YdSupplier> list = ydSupplierService.list(wrapper);
        return Result.success().put("data",list);
    }
    /**
     * 查询供应商
     * @return
     */
    @PostMapping("/supplierKHList")
    public Result supplierKHList(){
        LambdaQueryWrapper<YdSupplier> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(YdSupplier::getType,"客户");
        List<YdSupplier> list = ydSupplierService.list(wrapper);
        return Result.success().put("data",list);
    }
    /**
     * 查询所有商品
     * @return
     */
    @PostMapping("/materialList")
    public Result materialList(){
        List<YdMaterial> list = ydMaterialService.list();
        return Result.success().put("data",list);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PostMapping("/deleteOrder")
    public Result deleteOrder(@RequestBody Integer[] ids){
        for (int id : ids) {
            Boolean flag = ydDepotHeadService.deleteOrder(id);
        }
        return Result.success();
    }
    @PostMapping("/addPurchaseCGDD")
    public Result addPurchaseCGDD(@RequestBody PurchaseOrderVO purchaseOrderVO){
        return ydDepotHeadService.addPurchaseCGDD(purchaseOrderVO);
    }
}
